<template>
  <view class="content">
    <header-nav></header-nav>
    <env-data></env-data>
    <chart-water></chart-water>
    <chart-elec></chart-elec>
    <device-tj></device-tj>
    <chart-device></chart-device>
  </view>
</template>

<script>
import ChartWater from './components/ChartWater.vue'
import ChartElec from './components/ChartElec.vue'
import DeviceTj from './components/DeviceTj.vue'
import ChartDevice from './components/ChartDevice.vue'
import EnvData from './components/EnvData.vue'
import HeaderNav from './components/HeaderNav.vue'
import { mapState } from 'vuex'
export default {
  components: {
    ChartWater,
    ChartElec,
    DeviceTj,
    ChartDevice,
    EnvData,
    HeaderNav,
  },
  data() {
    return {}
  },
  computed: {
    ...mapState({
      currentProject: (state) => state.project.project,
    }),
  },
  onShareAppMessage() {
    console.log("分享小程序");
  },
  onLoad() {},
  mounted() {
    // 项目接口
    // this.$store.dispatch('project/getProjectList')
  },
  methods: {
  },
  watch: {
    /**
     * 项目切换统一监听
     */
    currentProject: function(val) {
      if (val.id) {
        this.$store.dispatch('project/fetchTodayPowerUsage', val.id)
        this.$store.dispatch('device/getDeviceCount', val.id)
        this.$store.dispatch('weather/today')
        this.$store.dispatch('project/fetchTodayWaterAndPower', val.id)
        this.$store.dispatch('device/getDeviceTypeCount', val.id)
        this.$store.commit('device/CLEAR_DEVICE_LIST')
        this.$store.dispatch('device/fetchFloors', {
          type: '传感器',
          projectId: val.id,
        })
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.content {
  padding: 32rpx;
}
</style>
